package control;

import java.sql.SQLException;
import java.util.HashMap;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import model.album.HappyAlbumService;
import model.album.AlbumListVO;
import model.member.MemberVO;

import org.springframework.web.servlet.ModelAndView;
import org.springframework.web.servlet.mvc.multiaction.MultiActionController;

public class HappyAlbumController extends MultiActionController{
	private HappyAlbumService happyAlbumService;

	public HappyAlbumController(HappyAlbumService happyAlbumService) {
		super();
		this.happyAlbumService = happyAlbumService;
	}
	public ModelAndView HappyTimeAlbumList(HttpServletRequest request,HttpServletResponse response){
		String page = request.getParameter("page");
		String optionalNoTest = request.getParameter("optionalNoTest");
		request.setAttribute("optionalNoTest", optionalNoTest);
		int optionalNo=Integer.parseInt(optionalNoTest); 	
		AlbumListVO listVO = null;
		try {
			listVO = happyAlbumService.HappyTimeAlbumList(page, optionalNo);
		} catch (SQLException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		System.out.println(listVO.toString());
		return new ModelAndView("album_list.happyalbum","happyList",listVO); 
	}
	public ModelAndView idcheck(HttpServletRequest request,HttpServletResponse response){
		String optionalNoTest = request.getParameter("optionalNoTest");
		int optionalNo = Integer.parseInt(optionalNoTest);
		MemberVO mvo=(MemberVO) request.getSession().getAttribute("mvo");
		HashMap map = new HashMap();
		map.put("optionalNo", optionalNo);
		map.put("id", mvo.getId());
		System.out.println(map.toString());
		boolean flag=true;
		try {
			flag = happyAlbumService.getIds(map);
		} catch (SQLException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		return new ModelAndView("JsonView","flag",flag);
	}
}
